<template>
  <div>
    <template v-for="item in this.menuList">
      <!-- 当循环出来的item中包含子菜单的时候,使用el-submenu否则使用菜单项el-menu-item -->
      <!-- :disabled="item.disabled" -->
      <!-- item.childMenus != null &&  -->
      <el-submenu
        :index="item.id + ''"
        v-if="item.childMenus != null && item.childMenus.length > 0"
        :key="item.id + ''"
      >
        <template slot="title" style="padding-left: 30px">
          <i :class="item.icon"></i>
          <span slot="title">{{ item.menuName }}</span>
        </template>
        <!-- 使用递归实现菜单的多级遍历 -->
        <MenuTree :menuList="item.childMenus"></MenuTree>
      </el-submenu>
      <el-menu-item
        v-else
        :index="item.url + ''"
        :route="item.url"
        @click="savePath(item.url)"
        :key="item.id + ''"
        style="padding-left: 50px"
      >
        <i :class="item.icon"></i>
        <span>{{ item.menuName }}</span>
      </el-menu-item>
    </template>
  </div>
</template>
<style>
.el-menu--collapse span,
.el-menu--collapse i.el-submenu__icon-arrow {
  height: 0;
  width: 0;
  overflow: hidden;
  visibility: hidden;
  display: inline-block;
}
</style>
<script>
import MenuTree from "./MenuTree.vue";
export default {
  name: "MenuTree", //模板名称
  data() {
    return {};
  },
  beforeMount() {},
  props: ["menuList", "tagList"],
  methods: {
    //保存激活路径
    savePath(path) {
      window.sessionStorage.setItem("activePath", path);
      this.activePath = path;
    },
  },
  created() {},
  components: {
    MenuTree,
  },
};
</script>
